#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
int n,m;
int aa[N],a[N];
int c[N],T;
int p[N];
int read(){
    char ch; int sum = 0,flag = 1;
    ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-') flag = -flag; ch = getchar();}
    while(ch >= '0' && ch <= '9'){sum = sum * 10 + ch - '0'; ch = getchar();}
    return flag * sum;
}
int bas[N],k;
int main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    n = read(); m = read();
    for(int i = 1; i <= n; i++){
        aa[i] = read();
    }
    for(int i = 1; i <= m; i++) c[i] = read();
    bas[0] = 1;
    for(int i = 1; i <= 31; i++) bas[i] = bas[i - 1] * 2;
    for(k = 0; k <= 31; k++){
        if(bas[k] >= n) break;
    }
    for(int i = 1; i <= n - k; i++){
        p[i] = read();
    }
    T = read();
    while(T--){
        int x[5];
        for(int i = 0; i <= 3; i++) x[i] = read();
        for(int i = 1; i <= n; i++){
            a[i] = aa[i] ^ x[i % 4];
        }
        cout << 0 << endl;
    }
    return 0;
}
